#ifndef MY_HEADER_H
#define MY_HEADER_H

#include <dirent.h>
#include <fcntl.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ipc.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>
#include <pthread.h>
#include <grp.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <sys/sendfile.h>
#include <sys/mman.h>
#include <mysql/mysql.h>
#include <openssl/md5.h>
#include <syslog.h>
#include <shadow.h>
//检查命令行参数数量是否符合预期
#define ARGS_CHECK(argc,expected)\
    do{\
     if((argc)!=(expected)){\
        fprintf(stderr,"args num error!\n");\
          exit(1);\
     }\
    }while(0)

//检查返回值是不是错误标记，若是则打印msg和错误信息
#define ERROR_CHECK(ret,error_flag,msg)\
    do{\
        if((ret)==(error_flag)){\
      perror(msg);\
      exit(1);\
      }\
           }while(0)

#define THREAD_ERROR_CHECK(ret,message)\
        do{\
            if(ret!=0){\
               fprintf(stderr,"%s : %s\n",message,strerror(ret));\
               exit(1);\
            }\
            }while(0);
#define LOG_CONNECT(username,cmd)\
{openlog("OnlineStorage",LOG_PID|LOG_CONS,LOG_LOCAL0);\
    syslog(LOG_INFO,"%s:connect,request message:%d\n",username,cmd);\
    closelog ();}

#define GETLOG(username,cmd)\
{openlog("OnlineStorage",LOG_PID|LOG_CONS,LOG_LOCAL0);\
    syslog(LOG_INFO,"%s,operation record:%d\n",username,cmd);\
    closelog ();}
#define LOG_ERROR(username,errbuf)\
{openlog("OnlineStorage",LOG_PID | LOG_CONS,LOG_LOCAL0);\
    syslog(LOG_ERR,"%s,error:%s\n",username,errbuf);\
closelog();}


#endif
